﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace AIC_CD
{
    public partial class BaoCaoCanBoDoanVienCongDoanDuocHocTapBoiDuong_Update : MyFromBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblNotice.Visible = false;

            CheckPermission();
            if (!IsPostBack)
            {
                Config();
                BindDataToControls();
            }
        }

        /// <summary>
        /// Thủ tục kiểm tra quyền sử dụng của người dùng có được quyền truy cập vào mục này hay không?
        /// </summary>
        private void CheckPermission()
        {
            Dictionary<string, int> Role = MyCommon.CheckPermission("CanBoDuocBoiDuongDaoTao");
            if (Role == null || Role["Xem"] == 0 || ((Role["Xem"] == 1 && Role["Sua"] == 0)))
            {
                Response.Redirect("Index.aspx?p=0");
            }
        }

        /// <summary>
        /// Thủ tục cấu hình giao diện, các controls
        /// </summary>
        private void Config()
        {
            //TODO
            txtThuTruongCoQuanChinhTri.Text = "";
        }

        /// <summary>
        /// Bind Data vào các contrls như Combobox, ListBox, textBox ...
        /// </summary>
        private void BindDataToControls()
        {
            string sql = "Select ID,TenDM From tblDanhMuc Where MaDM='" + MyConst.DanhMuc.KyBaoCao.Ma + "' ";
            SqlDataReader reKyBaoCao = SqlHelper.ExecuteReader(CommandType.Text, sql);
            clsDataBind.CreateCombo("Tất cả", reKyBaoCao, cboKyBaoCao, 1, 0);
        }

        /// <summary>
        /// Bind Data vào gridview
        /// </summary>
        private void BindDataToGrid()
        {
            bool IsEmpty = false;
            List<SqlParameter> arrParams = new List<SqlParameter>();
            arrParams.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
            arrParams.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, MyCommon.GetDonViID(Session["userid"].ToString())));

            string sql = "SELECT * FROM dbo.tblBaoCaoCanBoDoanVienCongDoanDuocHocTapBoiDuongDaoTao WHERE DonViID = @DonViID AND KyBaoCaoID_DM = @KyBaoCaoID_DM AND IsCommon = 0";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, arrParams);
            if (dt.Rows.Count == 0)
            {
                IsEmpty = true;
                DataRow dr = dt.NewRow();
                dr["HoTen"] = "";
                dr["QueQuan"] = "";
                dr["NamSinh"] = 0;
                dr["ChucVuCD"] = "";
                dr["ChucVuChinhQuyen"] = "";
                dr["TrinhDoChinhTri"] = "";
                dr["TrinhDoChuyenTrach"] = "";
                dr["TrinhDoCongDoan"] = "";
                dr["TrinhDoNgoaiNgu"] = "";
                dr["TrinhDoViTinh"] = "";
                dr["YeuCauDaoTaoBoiDuong"] = "";
                dt.Rows.InsertAt(dr, 0);

            }
            grvData.ShowFooter = true;
            grvData.DataSource = dt;
            grvData.DataBind();
            if (IsEmpty)
            {
                grvData.Rows[0].Visible = false;
            }
            BindDataToTextField();
        }

        protected void BindDataToTextField()
        {
            string sql = "SELECT * FROM dbo.tblBaoCaoCanBoDoanVienCongDoanDuocHocTapBoiDuongDaoTao WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND IsCommon = 1";
            List<SqlParameter> lstParameters = new List<SqlParameter>();
            lstParameters.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
            lstParameters.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, MyCommon.GetDonViID(Session["userid"].ToString())));
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParameters);
            if (dt.Rows.Count != 0)
            {
                txtTenBaoCao.Text = dt.Rows[0]["CM_TenBaoCao"].ToString();
                txtThuTruongCoQuanChinhTri.Text = dt.Rows[0]["CM_ThuTruong"].ToString();
            }
            else
            {
                txtTenBaoCao.Text = "";
                txtThuTruongCoQuanChinhTri.Text = "";
            }
        }

        #region Events

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("Index.aspx");
        }

        protected void cboKyBaoCao_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboKyBaoCao.SelectedIndex > 0)
            {
                btnLuu.Visible = true;
                grvData.Visible = true;
                grvData.EditIndex = -1;
                BindDataToGrid();
            }
            else
            {
                btnLuu.Visible = false;
                grvData.Visible = false;
            }
        }

        protected void btnLuu_Click(object sender, EventArgs e)
        {
            String sql = "SELECT * FROM dbo.tblBaoCaoCanBoDoanVienCongDoanDuocHocTapBoiDuongDaoTao WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND IsCommon = 1";
            List<SqlParameter> lstParameters = new List<SqlParameter>();
            lstParameters.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
            lstParameters.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, MyCommon.GetDonViID(Session["userid"].ToString())));

            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParameters);
            if (dt.Rows.Count == 0)
            {
                btnLuu.CommandName = MyConst.Action.Addnew;
            }
            else
            {
                btnLuu.CommandName = MyConst.Action.Update;
            }

            if (btnLuu.CommandName == MyConst.Action.Addnew)
            {
                string sSQL = "INSERT INTO dbo.tblBaoCaoCanBoDoanVienCongDoanDuocHocTapBoiDuongDaoTao" +
                              "(KyBaoCaoID_DM ,DonViID ,CM_ThuTruong ,CM_TenBaoCao ,CM_ThoiGianBaoCao" +
                              ",IsCommon ,CreateDate ,UpdateDate ,UserID)" +
                              "VALUES  ( @KyBaoCaoID_DM ,@DonViID ,@CM_ThuTruong ,@CM_TenBaoCao ," +
                              "GETDATE() ,1 ,GETDATE() ,GETDATE() ,@UserID)";

                List<SqlParameter> lstParameter = new List<SqlParameter>();
                lstParameter.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
                lstParameter.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, MyCommon.GetDonViID(Session["userid"].ToString())));
                lstParameter.Add(SqlHelper.CreateParameterObject("@CM_ThuTruong", SqlDbType.NVarChar, ParameterDirection.Input, txtThuTruongCoQuanChinhTri.Text.Trim()));
                lstParameter.Add(SqlHelper.CreateParameterObject("@CM_TenBaoCao", SqlDbType.NVarChar, ParameterDirection.Input, txtTenBaoCao.Text.Trim()));
                lstParameter.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(Session["userid"])));

                SqlHelper.ExecuteNonQuery(CommandType.Text, sSQL, lstParameter);
                MyCommon.AddMessage(this.Master, "Lưu thông tin báo cáo thành công", MyConst.MessageType.Success);
            }
            else
            {
                string sSQL = "Update tblBaoCaoCanBoDoanVienCongDoanDuocHocTapBoiDuongDaoTao Set CM_ThuTruong=@CM_ThuTruong, CM_TenBaoCao=@CM_TenBaoCao " +
                                "Where IsCommon=1 And DonViID=" + MyCommon.GetDonViID(Session["userid"].ToString()) + " And KyBaoCaoID_DM=" + cboKyBaoCao.SelectedValue;

                List<SqlParameter> lstParameter = new List<SqlParameter>();
                lstParameter.Add(SqlHelper.CreateParameterObject("@CM_ThuTruong", SqlDbType.NVarChar, ParameterDirection.Input, txtThuTruongCoQuanChinhTri.Text.Trim()));
                lstParameter.Add(SqlHelper.CreateParameterObject("@CM_TenBaoCao", SqlDbType.NVarChar, ParameterDirection.Input, txtTenBaoCao.Text.Trim()));


                SqlHelper.ExecuteNonQuery(CommandType.Text, sSQL, lstParameter);

                MyCommon.AddMessage(this.Master, "Lưu thông tin báo cáo thành công", MyConst.MessageType.Success);
            }
        }

        #endregion Events


        #region GridCommand

        private static void AddMergedCells(GridViewRow objgridviewrow, TableCell objtablecell, int colspan, int rowspan, string celltext)
        {
            objtablecell = new TableCell();
            objtablecell.Text = celltext;
            objtablecell.ColumnSpan = colspan;
            objtablecell.RowSpan = rowspan;
            objtablecell.HorizontalAlign = HorizontalAlign.Center;
            objgridviewrow.Cells.Add(objtablecell);
        }

        protected void grvData_RowCreated(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "STT");


                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Họ và tên");

                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Năm sinh");
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Chức vụ Công đoàn");
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Chức vụ chức quyền");
                AddMergedCells(objgridviewrow, objtablecell, 5, 1, "Trình độ");
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Yêu cầu đào tạo bồi dưỡng");

                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Sửa");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);

                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Chính trị");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Chuyên trách");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Công đoàn");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Ngoại ngữ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Vi tính");

                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);
            }
        }

        protected void grvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {


            RowDataBound(sender, e);
        }

        protected void grvData_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;


            if ((sCommandName == AIC_CD.MyConst.Action.Approve))
            {
                SqlTransaction MyTrans = SqlHelper.BeginTransaction();
                try
                {

                    // cap nhat vao database
                    TextBox txtHoTenEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtHoTenEdit");
                    TextBox txtNamSinhEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtNamSinhEdit");
                    TextBox txtChucVuCDEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtChucVuCDEdit");
                    TextBox txtChucVuCQEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtChucVuCQEdit");
                    TextBox txtCTriEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtCTriEdit");
                    TextBox txtCTrachEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtCTrachEdit");
                    TextBox txtCongDoanEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtCongDoanEdit");
                    TextBox txtNNguEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtNNguEdit");
                    TextBox txtViTinhEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtViTinhEdit");
                    TextBox txtYeuCauEdit = (TextBox)grvData.Rows[grvData.EditIndex].FindControl("txtYeuCauEdit");

                    string sSQL = "UPDATE tblBaoCaoCanBoDoanVienCongDoanDuocHocTapBoiDuongDaoTao " +
                                  "SET HoTen = @HoTen,NamSinh = @NamSinh,ChucVuCD = @ChucVuCD" +
                                  ",ChucVuChinhQuyen = @ChucVuChinhQuyen,TrinhDoChinhTri = @TrinhDoChinhTri,TrinhDoChuyenTrach = @TrinhDoChuyenTrach" +
                                  ",TrinhDoCongDoan = @TrinhDoCongDoan,TrinhDoNgoaiNgu = @TrinhDoNgoaiNgu,TrinhDoViTinh = @TrinhDoViTinh" +
                                  ",YeuCauDaoTaoBoiDuong = @YeuCauDaoTaoBoiDuong,UpdateDate = GETDATE(),UserID = @UserID WHERE ID = @ID";

                    List<SqlParameter> lstParameter = new List<SqlParameter>();

                    lstParameter.Add(SqlHelper.CreateParameterObject("@HoTen", SqlDbType.NVarChar, ParameterDirection.Input, txtHoTenEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@NamSinh", SqlDbType.Int, ParameterDirection.Input, txtNamSinhEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@ChucVuCD", SqlDbType.NVarChar, ParameterDirection.Input, txtChucVuCDEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@ChucVuChinhQuyen", SqlDbType.NVarChar, ParameterDirection.Input, txtChucVuCQEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoChinhTri", SqlDbType.NVarChar, ParameterDirection.Input, txtCTriEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoChuyenTrach", SqlDbType.NVarChar, ParameterDirection.Input, txtCTrachEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoCongDoan", SqlDbType.NVarChar, ParameterDirection.Input, txtCongDoanEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoNgoaiNgu", SqlDbType.NVarChar, ParameterDirection.Input, txtNNguEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoViTinh", SqlDbType.NVarChar, ParameterDirection.Input, txtViTinhEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@YeuCauDaoTaoBoiDuong", SqlDbType.NVarChar, ParameterDirection.Input, txtYeuCauEdit.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));

                    lstParameter.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, sID));

                    SqlHelper.ExecuteNonQuery(CommandType.Text, sSQL, lstParameter);
                    MyTrans.Commit();
                    grvData.EditIndex = -1;
                    BindDataToGrid();
                    MyCommon.AddMessage(this.Master, "Cập nhật thành công", MyConst.MessageType.Success);
                }
                catch (Exception)
                {
                    MyTrans.Rollback();
                }

            }
            else if (e.CommandName == AIC_CD.MyConst.Action.Addnew)
            {
                SqlTransaction MyTrans = SqlHelper.BeginTransaction();
                try
                {
                    TextBox txtHoTenNew = (TextBox)grvData.FooterRow.FindControl("txtHoTenNew");
                    TextBox txtNamSinhNew = (TextBox)grvData.FooterRow.FindControl("txtNamSinhNew");
                    TextBox txtChucVuCDNew = (TextBox)grvData.FooterRow.FindControl("txtChucVuCDNew");
                    TextBox txtChucVuCQNew = (TextBox)grvData.FooterRow.FindControl("txtChucVuCQNew");
                    TextBox txtCTriNew = (TextBox)grvData.FooterRow.FindControl("txtCTriNew");
                    TextBox txtCTrachNew = (TextBox)grvData.FooterRow.FindControl("txtCTrachNew");
                    TextBox txtCongDoanNew = (TextBox)grvData.FooterRow.FindControl("txtCongDoanNew");
                    TextBox txtNNguNew = (TextBox)grvData.FooterRow.FindControl("txtNNguNew");
                    TextBox txtViTinhNew = (TextBox)grvData.FooterRow.FindControl("txtViTinhNew");
                    TextBox txtYeuCauNew = (TextBox)grvData.FooterRow.FindControl("txtYeuCauNew");

                    string sql = "INSERT INTO dbo.tblBaoCaoCanBoDoanVienCongDoanDuocHocTapBoiDuongDaoTao " +
                                 "( KyBaoCaoID_DM ,DonViID ,HoTen ,NamSinh ,ChucVuCD ,ChucVuChinhQuyen ,TrinhDoChinhTri ,TrinhDoChuyenTrach ," +
                                 "TrinhDoCongDoan ,TrinhDoNgoaiNgu ,TrinhDoViTinh ,YeuCauDaoTaoBoiDuong ,CreateDate ,UpdateDate ,UserID,IsCommon)" +
                                 "VALUES  ( @KyBaoCaoID_DM ,@DonViID ,@HoTen ,@NamSinh ,@ChucVuCD ,@ChucVuChinhQuyen ,@TrinhDoChinhTri ,@TrinhDoChuyenTrach ," +
                                 "@TrinhDoCongDoan ,@TrinhDoNgoaiNgu ,@TrinhDoViTinh ,@YeuCauDaoTaoBoiDuong ,GETDATE() ,GETDATE() ,@UserID,0)";
                    List<SqlParameter> lstParameter = new List<SqlParameter>();
                    lstParameter.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(cboKyBaoCao.SelectedValue)));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, MyCommon.GetDonViID(Session["userid"].ToString())));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@HoTen", SqlDbType.NVarChar, ParameterDirection.Input, txtHoTenNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@NamSinh", SqlDbType.Int, ParameterDirection.Input, txtNamSinhNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@ChucVuCD", SqlDbType.NVarChar, ParameterDirection.Input, txtChucVuCDNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@ChucVuChinhQuyen", SqlDbType.NVarChar, ParameterDirection.Input, txtChucVuCQNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoChinhTri", SqlDbType.NVarChar, ParameterDirection.Input, txtCTriNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoChuyenTrach", SqlDbType.NVarChar, ParameterDirection.Input, txtCTrachNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoCongDoan", SqlDbType.NVarChar, ParameterDirection.Input, txtCongDoanNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoNgoaiNgu", SqlDbType.NVarChar, ParameterDirection.Input, txtNNguNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@TrinhDoViTinh", SqlDbType.NVarChar, ParameterDirection.Input, txtViTinhNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@YeuCauDaoTaoBoiDuong", SqlDbType.NVarChar, ParameterDirection.Input, txtYeuCauNew.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(Session["userid"].ToString())));

                    int Result = SqlHelper.ExecuteNonQuery(CommandType.Text, sql, lstParameter);
                    if (Result == 0)
                    {
                        MyCommon.AddMessage(this.Master, "Có lỗi xảy ra trong quá trình thêm mới", MyConst.MessageType.Error);
                    }
                    else
                    {
                        MyCommon.AddMessage(this.Master, "Thêm mới thành công !", MyConst.MessageType.Success);
                    }

                    MyTrans.Commit();
                    BindDataToGrid();
                }
                catch (Exception)
                {
                    MyTrans.Rollback();
                }
            }
            else if ((sCommandName == AIC_CD.MyConst.Action.Delete))
            {
                string sql = "DELETE FROM dbo.tblBaoCaoCanBoDoanVienCongDoanDuocHocTapBoiDuongDaoTao WHERE ID = @ID";
                List<SqlParameter> lstParameter = new List<SqlParameter>();

                lstParameter.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, sID));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, lstParameter);

                grvData.EditIndex = -1;
                BindDataToGrid();
                MyCommon.AddMessage(this.Master, "Xóa thành công !", MyConst.MessageType.Success);
            }
        }

        protected void grvData_RowEditing(object sender, GridViewEditEventArgs e)
        {
            grvData.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }



        protected void grvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }


        protected void grvData_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData.EditIndex = -1;
            BindDataToGrid();
        }

        #endregion GridCommand

        protected void grvData_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            grvData.DeleteRow(e.RowIndex);
            grvData.DataBind();
        }
    }
}
